<template>
  <div :class="{hyWrapper: needPlaceholder}">
    <div class="wrapper" v-for="(ban, idx) in banners" v-show="showIndex === idx">
      <a :href="ban.link">
        <img :src="ban.image" :alt="ban.title">
      </a>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Banner',
  props: {
    banners: {
      type: Array,
      default() {
        return []
      }
    },
    interval: {
      type: Number,
      default () {
        return 3000
      }
    }
  },
  data() {
    return {
      isLoad: false,
      showIndex: 0,
      needPlaceholder: false
    }
  },
  mounted () {
    this.isNeedPlaceholder();
    setInterval(() => {
      if (this.showIndex < this.banners.length -1) {
        this.showIndex ++;
      }else {
        this.showIndex = 0;
      }
    },this.interval)
  },
  methods: {
    isNeedPlaceholder() {
      if (this.banners.length < 1) {
        this.needPlaceholder = true;
      }
    },
    imageLoad() {
      if (!this.isLoad) {
        this.$emit('swiperImageLoad')
        this.isLoad = true
      }
    }
  }
}
</script>

<style scoped>
.hyWrapper {
  /*position: relative;*/
  /*overflow: hidden;*/
  height: 195px;
}

.wrapper {
  width: 100%;
  flex-shrink: 0;
}

.wrapper img {
  width: 100%;
}
</style>
